loadstring(exports.dgs:dgsImportFunction())()

local sw,sh = guiGetScreenSize()
local px,py = sw/1366,sh/768
font = dgsCreateFont( ":cmta-pobieraniezasobow/OSB.ttf", 25*px )
font2 = dgsCreateFont( ":cmta-pobieraniezasobow/OSB.ttf", 12*px )
font3 = dgsCreateFont( ":cmta-pobieraniezasobow/OSB.ttf", 10*px )

cmtaPANELGANGU = false
cmtaPANELGANGUULEPSZENIA = false
cmtaPANELGANGUDEPOZYT = false

amountmembers = 0

local gangMaxMembers = {
    ["0"] = {
        membersAmount = 12;
        upgradePrice = 10000;        
    };
    ["1"] = {
        membersAmount = 14;
        upgradePrice = 20000;        
    };
    ["2"] = {
        membersAmount = 16;
        upgradePrice = 35000;        
    };
    ["3"] = {
        membersAmount = 18;
        upgradePrice = 50000;        
    };
    ["4"] = {
        membersAmount = 20;
        upgradePrice = 70000;        
    };
    ["5"] = {
        membersAmount = 22;
        upgradePrice = 95000;        
    };
    ["6"] = {
        membersAmount = 24;
        upgradePrice = 120000;        
    };
    ["7"] = {
        membersAmount = 26;
        upgradePrice = 150000;        
    };
    ["8"] = {
        membersAmount = 28;
        upgradePrice = 190000;        
    };
    ["9"] = {
        membersAmount = 30;
        upgradePrice = 250000;        
    };
    ["10"] = {
        membersAmount = 32;
        upgradePrice = 0;        
    };
}

local gangMaxCars = {
    ["0"] = {
        carsAmount = 8;
        upgradePrice = 10000;        
    };
    ["1"] = {
        carsAmount = 11;
        upgradePrice = 20000;        
    };
    ["2"] = {
        carsAmount = 14;
        upgradePrice = 35000;        
    };
    ["3"] = {
        carsAmount = 17;
        upgradePrice = 50000;        
    };
    ["4"] = {
        carsAmount = 20;
        upgradePrice = 70000;        
    };
    ["5"] = {
        carsAmount = 23;
        upgradePrice = 95000;        
    };
    ["6"] = {
        carsAmount = 26;
        upgradePrice = 120000;        
    };
    ["7"] = {
        carsAmount = 29;
        upgradePrice = 150000;        
    };
    ["8"] = {
        carsAmount = 32;
        upgradePrice = 190000;        
    };
    ["9"] = {
        carsAmount = 35;
        upgradePrice = 250000;        
    };
    ["10"] = {
        carsAmount = 38;
        upgradePrice = 0;        
    };
}

local gangEquipment = {
    ["0"] = {
        Weapons = "[ [ [22, 30] ] ]";
        Kevlar = 0;
        weaponsDescription = "Colt-45 [30 ammo]";
        upgradePrice = 15000;        
    };
    ["1"] = {
        Weapons = "[ [ [22, 60] ] ]";
        Kevlar = 0;
        weaponsDescription = "Colt-45 [60 ammo]";
        upgradePrice = 25000;        
    };
    ["2"] = {
        Weapons = "[ [ [24, 30] ] ]";
        Kevlar = 0;
        weaponsDescription = "Deagle [30 ammo]";
        upgradePrice = 40000;        
    };
    ["3"] = {
        Weapons = "[ [ [24, 60] ] ]";
        Kevlar = 20;
        weaponsDescription = "Deagle [60 ammo]\nKevlar 20%";
        upgradePrice = 70000;        
    };
    ["4"] = {
        Weapons = "[ [ [24, 60], [28, 30] ] ]";
        Kevlar = 20;
        weaponsDescription = "Deagle [60 ammo]\nUZI [30 ammo]\nKevlar 20%";
        upgradePrice = 100000;        
    };
    ["5"] = {
        Weapons = "[ [ [24, 60], [28, 60] ] ]";
        Kevlar = 30;
        weaponsDescription = "Deagle [60 ammo]\nUZI [60 ammo]\nKevlar 30%";
        upgradePrice = 140000;        
    };
    ["6"] = {
        Weapons = "[ [ [24, 120], [28, 120] ] ]";
        Kevlar = 40;
        weaponsDescription = "Deagle [120 ammo]\nUZI [120 ammo]\nKevlar 40%";
        upgradePrice = 190000;        
    };
    ["7"] = {
        Weapons = "[ [ [24, 120], [28, 120], [30, 30] ] ]";
        Kevlar = 60;
        weaponsDescription = "Deagle [120 ammo]\nUZI [120 ammo]\nAK-47 [30 ammo]\nKevlar 60%";
        upgradePrice = 250000;        
    };
    ["8"] = {
        Weapons = "[ [ [24, 120], [28, 120], [30, 60] ] ]";
        Kevlar = 80;
        weaponsDescription = "Deagle [120 ammo]\nUZI [120 ammo]\nAK-47 [60 ammo]\nKevlar 80%";
        upgradePrice = 330000;        
    };
    ["9"] = {
        Weapons = "[ [ [24, 120], [28, 120], [30, 120], [34, 10] ] ]";
        Kevlar = 100;
        weaponsDescription = "Deagle [120 ammo]\nUZI [120 ammo]\nAK-47 [120 ammo]\nSniper Rifle [10 ammo]\nKevlar 100%";
        upgradePrice = 500000;        
    };
    ["10"] = {
        Weapons = "[ [ [24, 120], [28, 120], [30, 120], [34, 20], [18, 15] ] ]";
        Kevlar = 100;
        weaponsDescription = "Deagle [120 ammo]\nUZI [120 ammo]\nAK-47 [120 ammo]\nSniper Rifle [20 ammo]\nMolotov [15 szt]\nKevlar 100%";
        upgradePrice = 0;        
    };
}

local gangPoliceChance = {
    ["0"] = {
        Chance = 80;    
        upgradePrice = 5000;        
    };
    ["1"] = {
        Chance = 75;    
        upgradePrice = 15000;        
    };
    ["2"] = {
        Chance = 70;    
        upgradePrice = 30000;        
    };
    ["3"] = {
        Chance = 65;    
        upgradePrice = 50000;        
    };
    ["4"] = {
        Chance = 60;    
        upgradePrice = 80000;        
    };
    ["5"] = {
        Chance = 55;    
        upgradePrice = 120000;        
    };
    ["6"] = {
        Chance = 50;    
        upgradePrice = 170000;        
    };
    ["7"] = {
        Chance = 45;    
        upgradePrice = 230000;        
    };
    ["8"] = {
        Chance = 40;    
        upgradePrice = 300000;        
    };
    ["9"] = {
        Chance = 35;    
        upgradePrice = 350000;        
    };
    ["10"] = {
        Chance = 30;    
        upgradePrice = 0;        
    };
}

local gangRanksName = {
    ["1"] = {
        rankName = "Rekrut";
    };
    ["2"] = {
        rankName = "Gangster";
    };
    ["3"] = {
        rankName = "Fachowiec";
    };
    ["4"] = {
        rankName = "Mafiozo";
    };
    ["5"] = {
        rankName = "Weteran";
    };
    ["6"] = {
        rankName = "Killer";
    };
    ["7"] = {
        rankName = "Ojciec Chrzestny";
    };
    ["8"] = {
        rankName = "Zastępca Szefa";
    };
    ["9"] = {
        rankName = "Szef";
    };
}

addEvent("cmta_gangs:showGUI", true)
addEventHandler("cmta_gangs:showGUI", resourceRoot, function(result,result2)
    if cmtaPANELGANGUULEPSZENIA then return end
    if cmtaPANELGANGU then
        cmtaPANELGANGU = false
        destroyElement(rndRect)
        destroyElement(rect)
        showCursor(false)
        removeEventHandler ( "onDgsMouseClick", getRootElement(), onclick)
    else
        rndRect = dgsCreateRoundRect(0,false,tocolor(30,30,30,230))  
        rect = dgsCreateImage(500*px,150*py,366*px,468*py,rndRect,false)
        button = dgsCreateButton( 50*px, 200*py, 266*px, 40*py, "Członkowie", false,rect,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
        button2 = dgsCreateButton( 50*px, 250*py, 266*px, 40*py, "Ulepszenia", false,rect,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
        button3 = dgsCreateButton( 50*px, 300*py, 266*px, 40*py, "Depozyt", false,rect,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
        button4 = dgsCreateButton( 50*px, 350*py, 266*px, 40*py, "Historia działań", false,rect,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
        cmtaPANELGANGU = true
        showCursor(true)
        upgrds=split(tostring(result2[1].upgrades), ",")
        napisy(result,result2)
        addEventHandler ( "onDgsMouseClick", getRootElement(), onclick)
    end
end)

function onclick ( btn, state )
    if btn == "left" and state == "down" and cmtaPANELGANGU == true then
        if source == button2 then
            dgsSetEnabled(rect,false)
            dgsSetAlpha(rect,0.2)
            cmtaPANELGANGUULEPSZENIA = true
            rndRectulep = dgsCreateRoundRect(0,false,tocolor(30,30,30,250))  
            rectulep = dgsCreateImage(225*px,175*py,866*px,368*py,rndRectulep,false)
            textulep1 = dgsCreateLabel(0*px,30*py,266*px,50*py,"",false,rectulep)
            dgsSetFont( textulep1, font3 )
            dgsSetProperty(textulep1,"colorcoded",true)
            dgsSetProperty(textulep1,"alignment",{"center","top"})
            textulep2 = dgsCreateLabel(200*px,30*py,266*px,50*py,"",false,rectulep)
            dgsSetFont( textulep2, font3 )
            dgsSetProperty(textulep2,"colorcoded",true)
            dgsSetProperty(textulep2,"alignment",{"center","top"})
            textulep3 = dgsCreateLabel(400*px,30*py,266*px,50*py,"",false,rectulep)
            dgsSetFont( textulep3, font3 )
            dgsSetProperty(textulep3,"colorcoded",true)
            dgsSetProperty(textulep3,"alignment",{"center","top"})
            textulep4 = dgsCreateLabel(600*px,30*py,266*px,50*py,"",false,rectulep)
            dgsSetFont( textulep4, font3 )
            dgsSetProperty(textulep4,"colorcoded",true)
            dgsSetProperty(textulep4,"alignment",{"center","top"})
            buttonulep = dgsCreateButton( 50*px, 230*py, 166*px, 40*py, "Ulepsz", false,rectulep,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            buttonulep2 = dgsCreateButton( 250*px, 230*py, 166*px, 40*py, "Ulepsz", false,rectulep,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            buttonulep3 = dgsCreateButton( 450*px, 230*py, 166*px, 40*py, "Ulepsz", false,rectulep,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            buttonulep4 = dgsCreateButton( 650*px, 230*py, 166*px, 40*py, "Ulepsz", false,rectulep,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            buttonulep5 = dgsCreateButton( 300*px, 310*py, 266*px, 40*py, "Zamknij", false,rectulep,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))

            triggerServerEvent("cmta_gangs:refreshulep", resourceRoot)
        end
       --[[ if source == button3 then
            dgsSetEnabled(rect,false)
            dgsSetAlpha(rect,0.2)
            cmtaPANELGANGUDEPOZYT = true
            rndRectdepo = dgsCreateRoundRect(0,false,tocolor(30,30,30,250))  
            rectdepo = dgsCreateImage(300*px,150*py,766*px,468*py,rndRectdepo,false)

        end]]
        if source == buttonulep5 then
            destroyElement(rndRectulep)
            destroyElement(rectulep)
            dgsSetEnabled(rect,true)
            dgsSetAlpha(rect,1)
            cmtaPANELGANGUULEPSZENIA = false
        end
    end
end

function napisy(result,result2)
    amountmembers = 0
    for i,v in pairs(result) do
    if v["gang_name"] == getElementData(localPlayer,"player:gang") then
    amountmembers = amountmembers+1
    end
    end
    local amountmembersz = gangMaxMembers[upgrds[1]]
    local amountmembers2 = amountmembersz.membersAmount
    
    text = dgsCreateLabel(0*px,30*py,366*px,50*py,"#ff0000"..result2[1]["name"].."",false,rect)
    dgsSetFont( text, font )
    dgsSetProperty(text,"colorcoded",true)
    dgsSetProperty(text,"alignment",{"center","center"})
    text1 = dgsCreateLabel(0*px,100*py,366*px,50*py,"#FFFFFFPoziom Gangu: #ff0000"..result2[1]["level"].."\n#FFFFFFCzłonkowie: #ff0000"..amountmembers.."/"..amountmembers2.."\n#FFFFFFTwój stopień: #ff0000"..(gangRanksName[tostring(result[1]["rank"])].rankName).." ["..result[1]["rank"].."]",false,rect)
    dgsSetFont( text1, font2 )
    dgsSetProperty(text1,"colorcoded",true)
    dgsSetProperty(text1,"alignment",{"center","center"})
end
    
addEvent("cmta_gangs:refresh", true)
addEventHandler("cmta_gangs:refresh", resourceRoot, function(result)
    local upgr=split(tostring(result[1].upgrades), ",")
    
    dgsSetText(textulep1,"#ff0000LICZBA CZŁONKÓW\n\n#808080Limit: #ff0000"..(gangMaxMembers[upgr[1]].membersAmount).."#ccc000+2\n#808080Ulepszenia: #ff0000"..upgrds[1].."/10\n#808080Koszt ulepszenia: #ff0000"..(gangMaxMembers[upgr[1]].upgradePrice).." pkt")
    dgsSetText(textulep2,"#ff0000LICZBA POJAZDÓW\n\n#808080Limit: #ff0000"..(gangMaxCars[upgr[2]].carsAmount).."#ccc000+3\n#808080Ulepszenia: #ff0000"..upgrds[2].."/10\n#808080Koszt ulepszenia: #ff0000"..(gangMaxCars[upgr[2]].upgradePrice).." pkt")
    dgsSetText(textulep3,"#ff0000WYPOSAŻENIE\n\n#808080Dostępne:\n#ff0000"..(gangEquipment[upgr[3]].weaponsDescription).."\n#808080Ulepszenia: #ff0000"..upgrds[3].."/10\n#808080Koszt ulepszenia: #ff0000"..(gangEquipment[upgr[3]].upgradePrice).." pkt")
    dgsSetText(textulep4,"#ff0000DYSKRECJA\n\n#808080Szansa na policję\npodczas napadu:#ff0000"..(gangPoliceChance[upgr[4]].Chance).."%#ccc000-5%\n#808080Ulepszenia: #ff0000"..upgrds[4].."/10\n#808080Koszt ulepszenia: #ff0000"..(gangPoliceChance[upgr[4]].upgradePrice).." pkt")


end)